import os
from flask import Flask
import base64

app = Flask(__name__, static_folder='static')

# 设置项目根目录和下载目录的路径
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))


# 图标文件的 Base64 编码
FAVICON_ICO = """
[Base64 encoded favicon.ico content]
"""

FAVICON_PNG = """
[Base64 encoded favicon-32x32.png content]
"""

# 在启动时生成图标文件
def generate_icons():
    static_dir = os.path.join(PROJECT_ROOT, 'static')
    os.makedirs(static_dir, exist_ok=True)
    
    # 写入 favicon.ico
    with open(os.path.join(static_dir, 'favicon.ico'), 'wb') as f:
        f.write(base64.b64decode(FAVICON_ICO))
    
    # 写入 favicon-32x32.png
    with open(os.path.join(static_dir, 'favicon-32x32.png'), 'wb') as f:
        f.write(base64.b64decode(FAVICON_PNG))


if __name__ == '__main__':
    generate_icons()